$(document).ready(function() {
	var isLoadIframe = false;
	var isLoadInfo = false;
	var json = null;
	$('#save').bind('click', function() {
		var data = iframe.window.save();
		$.post('ajax_set_application_info', {
			id : $('#application_id').val(),
			name:$('#name').val(),
			context:$('#context').val(),
			data:JSON.stringify(data)
		}, function(data, status) {

			if (status == 'success') {
				if (data.type == 0) {
					alert("成功");
					location.href = 'ShowApplication?id=' + $('#application_id').val();
				}else{
					alert(data.msg);
					if(data.type == -1){
						location.href = 'Login';
					}
				}
			} else {
				alert("网络错误");
				location.href = 'Index';
			}
		});
	});

	iframe.window.onload = function() {
		isLoadIframe = true;
		if (isLoadInfo && isLoadIframe) {
			iframe.window.init(json.data);
		}
	}

	$.post('ajax_get_application_info', {
		id : $('#application_id').val()
	}, function(data, status) {
		if (status == 'success') {
			if (data.type >= 0) {
				isLoadInfo = true;
				json = data;
				if (isLoadInfo && isLoadIframe) {
					iframe.window.init(json.data);
				}
			}else{
				alert(data.msg);
			}
		} else {
			alert("网络错误");
		}
	});

});